package com.jason.quectel0805.activities;

import android.os.Bundle;

import com.jason.quectel0805.R;
import com.jason.quectel0805.adapters.JasonFragmentPagerAdapter;
import com.jason.quectel0805.fragments.MyFragment;

import java.util.ArrayList;
import java.util.List;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

public class MyViewPagerFragmentActivity extends AppCompatActivity {

    private ViewPager viewPager;
    private List<Fragment> list = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_view_pager_fragment);
        //初始化Viewpager
        viewPager = findViewById(R.id.viewpager_fragment_show);
        list.add(MyFragment.newInstance("首页"));
        list.add(MyFragment.newInstance("商城"));
        list.add(MyFragment.newInstance("购物车"));
        list.add(MyFragment.newInstance("消息"));
        list.add(MyFragment.newInstance("我的"));
        //    创建适配器
        JasonFragmentPagerAdapter adapter = new JasonFragmentPagerAdapter(getSupportFragmentManager(), list);
        //绑定适配器
        viewPager.setAdapter(adapter);
    }
}